#ifndef _ARRAY_H
#define _ARRAY_H

#include <iostream>

class Array
{
private:
	int arrayLength;
	int* arrayPointer;
	Array(int length);
	Array(const Array& obj);
	bool construct();
public:
	static Array* newinstance(int length);
	int length();
	bool set(int index, int value);
	bool get(int index, int& value);
	int& operator [] (const int index);
	Array& self();
	~Array();
};

Array::Array(int length)
{
	arrayLength = length;
}

Array::Array(const Array& obj)
{
	
}

bool Array::construct()
{
	bool ret = true;
	arrayPointer = new int[arrayLength];
	if(arrayPointer == nullptr)
	{
		ret = false;
	}
	return ret;
}

Array* Array::newinstance(int length)
{
	Array* ret = new Array(length);
	if(!(ret && ret->construct()))
	{
		delete ret;
		ret = nullptr;
	}
	return ret;
}

int Array::length()
{
	return arrayLength;
}

bool Array::set(int index, int value)
{
	bool ret = true;
	if(index >= 0 && index < length())
	{
		arrayPointer[index] = value;
	}
	else
	{
		ret = false;
	}
	return ret;
}

bool Array::get(int index, int& value)
{
	bool ret = true;
	if(index >= 0 && index < length())
	{
		value = arrayPointer[index];
	}
	else
	{
		ret = false;
	}
	return ret;
}

int& Array::operator [] (const int index)
{
	return arrayPointer[index];
}

Array& Array::self()
{
	return *this;
}

Array::~Array()
{
	delete[] arrayPointer;
}

#endif   //_ARRAY_H

